package com.wanmait.schedule.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.schedule.entity.Classes;
import com.wanmait.schedule.entity.Course;
import com.wanmait.schedule.entity.CoursePlan;
import com.wanmait.schedule.entity.Teacher;
import com.wanmait.schedule.service.ClassesService;
import com.wanmait.schedule.service.CoursePlanService;
import com.wanmait.schedule.service.CourseService;
import com.wanmait.schedule.service.TeacherService;
import com.wanmait.schedule.util.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程计划表 前端控制器
 * </p>
 *
 * @author wanmait
 * @since 2022-12-05
 */
@RestController
@RequestMapping("/manage/coursePlan")
@RequiresPermissions("manage:course_plan")
public class CoursePlanController {

    @Autowired
    private CoursePlanService coursePlanService;

    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    /**
     * 计划列表 分页 模糊搜索
     * @param coursePlan
     * @param pageNum
     * @return
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody CoursePlan coursePlan,Integer pageNum){
        PageInfo<CoursePlan> pageInfo = coursePlanService.findAll(coursePlan, pageNum);
        return AjaxResult.success("成功").put("pageInfo",pageInfo);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    public AjaxResult findById(@PathVariable("id") Integer id){
        Classes byId = coursePlanService.findById(id);
        return AjaxResult.success("成功").put("classes",byId);
    }

    /**
     * 获得所有课程
     * @return
     */

    @GetMapping("/findAllCourse")
    public AjaxResult findAllCourse(){
        List<Course> courseList = courseService.findAll();
        return AjaxResult.success("成功").put("courseList",courseList);
    }

    /**
     * 根据课程id 获得教师
     * @param id
     * @return
     */
    @GetMapping("/findCourseIdByTeacher/{id}")
    public AjaxResult findCourseIdByTeacher(@PathVariable("id") Integer id){
        List<Teacher> teacherList = coursePlanService.findCourseIdByTeacher(id);
        return AjaxResult.success("成功").put("teacherList",teacherList);
    }


    @PostMapping("/save")
    public AjaxResult coursePlanSave(@RequestBody Map map){
        coursePlanService.save(map);

        return AjaxResult.success("成功");
    }


}
